# _*_ coding:utf-8 _*_
# @Time      : 23:14
# @Author    :baizhou
import uuid

import cv2
from matplotlib import pyplot as plt
import imutils
from skimage import exposure,io
import os
from django.conf import settings



def equalizeHistImage(path):
    '''
    直方图均衡化
    :param path:图像的保存路径
    :return: 返回均衡化处理后的图片
    '''
    image = cv2.imread(path)


    image_yuv = cv2.cvtColor(image, cv2.COLOR_BGR2YUV)
    # 直方图均衡化
    image_yuv[:, :, 0] = cv2.equalizeHist(image_yuv[:, :, 0])
    # 显示效果
    output = cv2.cvtColor(image_yuv, cv2.COLOR_YUV2BGR)
    upload_dir = os.path.join(settings.DEAL_DIR)
    suffix_file = path.split(".")[-1]
    # 文件名
    file_name = str(uuid.uuid1()) + "." + suffix_file
    save_path = os.path.join(upload_dir, file_name)
    cv2.imwrite(save_path, output)
    return file_name




